<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>KindEditor Unittest</title>
		<!-- <script src="../lib/firebug-lite/build/firebug-lite.js#startOpened"></script> -->
        <script>window.rnd = function(){ return Math.random() }</script>
		<script src="../publish/dist/kindeditor-all.js"></script>
        <style>
            .ke-icon-plugin-demo{
                background: url(./icons/plugin.svg) center center no-repeat!important;
                background-size: auto 80%!important;
            }

            .ke-toolbar-icon{
                width:24px!important;
                height: 24px!important;
                font-size: 14px!important;
            }
        </style>
	</head>
	<body>
        <div id="wrapper" style="padding:20px">
            <h1 id="qunit-header">KindEditor</h1>
            <div style="margin-left: 4vw;">
                <textarea  id="editor" cols="30" rows="10" style="width:90%;;margin-left:15px;"></textarea>
            </div>
        </div>
	</body>
    <script>
        // 初始化编辑器
        KindEditor.ready(function (K) {
            var options = {
                themesPath: '../themes/',
                basePath:'../',
                resizeType: 1,
                pasteType: 2,//0:禁止粘贴, 1:纯文本粘贴, 2:HTML粘贴
                height: 420,
                autoHeightMode: false,
                fixToolBar: true,
                fixToolBarWatchRef: '#wrapper',
                scrollToEditingTarget: false,
                emojiConfig:function(emojis, page){
                    page.cols = 12
                },
                symbolConfig:function(symbols, page){
                    page.cols = 9
                },
                // allowPreviewEmoticons: false,
                allowImageUpload: true,
                allowFlashUpload: false,
                formatUploadUrl: false,
                allowFileManager: false,
                allowImageRemote: true,
                uploadJson: '/handler/upload-test/',
                uploadHeader:{
                    corefx: 'mhalo',
                    time: new Date() * 1
                },
                extraFileUploadParams:{
                    'paramA': 'A'
                },
                uploadResponseFilter: function(response){
                    return response.data
                },
                imageSizeLimit: '2MB',
                items: K.Tools.All,
                cssData: 'body{font-size: 16px;line-height: 28px;}',
                afterBlur: function () {
                    this.sync();
                },
                afterChange: function(){
                    // console.info(event)
                }
            };
            var contentEditor = K.create('#editor', options);

            var html = Array.from({length: 3}).map(function(o,i){ return  '<p>'+ i +'</p>' }).join("")
            // html += '<p><img src="http://res.henandingdang.com/guanwang/Article/20170228/20170228155437.jpg"/></p><p>xxxxx</p>';
            contentEditor.html(html);

            contentEditor.edit.doc.addEventListener('paste', function (e) {
                var clipboardData = e.clipboardData;
                if (!(clipboardData && clipboardData.items)) {
                    return;
                }
                for (var i = 0, len = clipboardData.items.length; i < len; i++) {
                    var item = clipboardData.items[i];
                    if (item.kind === "file") {
                        var pasteFile = item.getAsFile();
                        var reader = new FileReader();
                        reader.readAsDataURL(pasteFile);
                        reader.onload = function () {
                            contentEditor.insertHtml("<img src='"+ reader.result +"' />")
                        }
                    }
                }
            })


            });
    
        
    </script>
</html>
